package vista.pasos;

import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JRadioButton;

import modelo.RangoPrecio;


@SuppressWarnings("serial")
public class FiltroPrecio extends Paso {

	private JRadioButton rdbtnRango1;
	private JRadioButton rdbtnRango2;
	private JRadioButton rdbtnRango3;
	private JRadioButton rdbtnRango4;
	private JRadioButton rdbtnRango5;
	private JRadioButton rdbtnRango6;
	private ButtonGroup rdbtnGroup;
	
	public FiltroPrecio() {
		
		JLabel lblPaso = new JLabel("Precio");
		add(lblPaso, "cell 0 0,alignx left,aligny center");
		
		JLabel lblCualEsEl = new JLabel("\u00BFCu\u00E1l es el precio m\u00E1ximo que est\u00E1 dispuesto a pagar por su nueva PC?");
		add(lblCualEsEl, "cell 0 2 4 1,alignx left,aligny center");
		
		rdbtnRango1 = new JRadioButton("menor a $1500");
		rdbtnRango1.setActionCommand(RangoPrecio.MuyBajo.name());
		add(rdbtnRango1, "cell 1 3,alignx left,aligny center");
		
		rdbtnRango2 = new JRadioButton("hasta $2000");
		rdbtnRango2.setActionCommand(RangoPrecio.Bajo.name());
		add(rdbtnRango2, "cell 1 4");
		
		rdbtnRango3 = new JRadioButton("hasta $3000");
		rdbtnRango3.setActionCommand(RangoPrecio.MedioBajo.name());
		add(rdbtnRango3, "cell 1 5");
		
		rdbtnRango4 = new JRadioButton("hasta $3500");
		rdbtnRango4.setActionCommand(RangoPrecio.Medio.name());
		add(rdbtnRango4, "cell 1 6");
		
		rdbtnRango5 = new JRadioButton("hasta $4000");
		rdbtnRango5.setActionCommand(RangoPrecio.MedioAlto.name());
		add(rdbtnRango5, "cell 1 7");
		
		rdbtnRango6 = new JRadioButton("mayor a $4000");
		rdbtnRango6.setActionCommand(RangoPrecio.MuyAlto.name());
		add(rdbtnRango6, "cell 1 8");
		
		rdbtnGroup = new ButtonGroup();
	    rdbtnGroup.add(rdbtnRango1);
	    rdbtnGroup.add(rdbtnRango2);
	    rdbtnGroup.add(rdbtnRango3);
	    rdbtnGroup.add(rdbtnRango4);
	    rdbtnGroup.add(rdbtnRango5);
	    rdbtnGroup.add(rdbtnRango6);
	    
	}

	@Override
	protected void ejecutarPaso() {
		getSeleccion().setPrecio(RangoPrecio.desdeDescripcion(rdbtnGroup.getSelection().getActionCommand()));
	}

	@Override
	protected boolean haySeleccion() {
		return (rdbtnGroup.getSelection() != null);
	}

	@Override
	protected void limpiarPaso() {
		rdbtnGroup.clearSelection();
	}
}
